package com.jiang.myfm.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jiang.myfm.R;
import com.jiang.myfm.entities.mianpage.ListEditorRecommendAlbums;
import com.jiang.myfm.newview.CustomRelativeLayout;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by dell on 2016/12/9 0009.
 */
public class MainRecyclerAdapterTwo extends RecyclerView.Adapter<MainRecyclerAdapterTwo.ViewHolder> {
    private List<ListEditorRecommendAlbums> mMainRecyclerTwoDataList;
    private Context context;

    public MainRecyclerAdapterTwo(List<ListEditorRecommendAlbums> mainRecyclerTwoDataList, Context context) {
        mMainRecyclerTwoDataList = mainRecyclerTwoDataList;
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.list_item_main_recycler_one, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.mCustomRelativeLayout.setMaxHeight((int) (context.getResources().getDisplayMetrics().widthPixels / 2.5));
        Picasso.with(context).load(mMainRecyclerTwoDataList.get(position).getAlbumCoverUrl290()).into(holder.mImageView);
        holder.mTextViewTitle.setText(mMainRecyclerTwoDataList.get(position).getTitle());
        holder.mTextViewTags.setText(mMainRecyclerTwoDataList.get(position).getTrackTitle());
    }

    @Override
    public int getItemCount() {
        return mMainRecyclerTwoDataList != null ? mMainRecyclerTwoDataList.size() : 0;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        private ImageView mImageView;
        private TextView mTextViewTags, mTextViewTitle;
        private CustomRelativeLayout mCustomRelativeLayout;

        public ViewHolder(View itemView) {
            super(itemView);
            mImageView = (ImageView) itemView.findViewById(R.id.list_item_main_recycler_one_iv);
            mTextViewTags = (TextView) itemView.findViewById(R.id.list_item_main_recycler_one_tv2);
            mTextViewTitle = (TextView) itemView.findViewById(R.id.list_item_main_recycler_one_tv1);
            mCustomRelativeLayout = (CustomRelativeLayout) itemView.findViewById(R.id.list_item_main_recycler_one_rl);
        }
    }

    public void addAll(List<ListEditorRecommendAlbums> list) {
        mMainRecyclerTwoDataList.addAll(list);
        notifyDataSetChanged();
    }
}
